package com.exception;

import com.po.Admininfo;
import com.po.Buyerinfo;
import com.po.Sellerinfo;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

public class MyExceptionHandler implements HandlerExceptionResolver {
	@Override
	public ModelAndView resolveException(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2,
			Exception arg3) {
	   	Map<String, Object> model = new HashMap<String, Object>();  
        model.put("ex", arg3); 
        // ���ݲ�ͬ����ת��ͬҳ��  
       if(arg3 instanceof AdminLoginNoException){
        	//��¼ҳ����Ҫadmin����
        	arg0.setAttribute("admin", new Admininfo());//����po��Admininfo��Ķ���admin
        	arg0.setAttribute("msg", "还没登陆，请重新登录！");
        	return new ModelAndView("/admin/login", model);
        } else if(arg3 instanceof BuyerLoginNoException){
        	arg0.setAttribute("buyer", new Buyerinfo());//ͬ����po��Buyerinfo��Ķ���buyer
        	arg0.setAttribute("msg", "还没登陆，请重新登录！");
        	return new ModelAndView("/buyer/login", model);
       }else if(arg3 instanceof SellerLoginNoException){
		   arg0.setAttribute("seller", new Sellerinfo());//ͬ����po��Buyerinfo��Ķ���buyer
		   arg0.setAttribute("msg", "还没登陆，请重新登录！");
		   return new ModelAndView("/seller/login", model);
	   }
       else{
        	return new ModelAndView("/error/error", model);  
        }  
	}
}
